package cn.zhpdmmz.hotel.controller;

import cn.zhpdmmz.entity.ReservationInformationDetail;
import cn.zhpdmmz.service.IReservationInformationDetailService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
/**
 * (ReservationInformationDetail)表控制层
 *
 * @author CJW
 * @since 2022-04-23 01:28:45
 */
@RestController
@RequestMapping("reservationInformationDetail")
public class ReservationInformationDetailController {
    /**
     * 服务对象
     */
    @Autowired
    private IReservationInformationDetailService reservationInformationDetailService;

    /**
     * 分页查询
     *
     * @param reservationInformationDetail 筛选条件
     * @return 查询结果
     */
    @GetMapping("/list")
    public ResponseEntity<List<ReservationInformationDetail>> queryAll(ReservationInformationDetail reservationInformationDetail) {
        return ResponseEntity.ok(this.reservationInformationDetailService.queryAll(reservationInformationDetail));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<ReservationInformationDetail> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.reservationInformationDetailService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param reservationInformationDetail 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<ReservationInformationDetail> add(@RequestBody ReservationInformationDetail reservationInformationDetail) {
        return ResponseEntity.ok(this.reservationInformationDetailService.insert(reservationInformationDetail));
    }

    /**
     * 编辑数据
     *
     * @param reservationInformationDetail 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<ReservationInformationDetail> edit(@RequestBody ReservationInformationDetail reservationInformationDetail) {
        return ResponseEntity.ok(this.reservationInformationDetailService.update(reservationInformationDetail));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/delete/{id}")
    public ResponseEntity<Boolean> deleteById(@PathVariable Integer id) {
        return ResponseEntity.ok(this.reservationInformationDetailService.deleteById(id));
    }

    @GetMapping("/page")
    public PageInfo page(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize, ReservationInformationDetail reservationInformationDetail) {
        PageHelper.startPage(pageNum,pageSize);
        List<ReservationInformationDetail> list = this.reservationInformationDetailService.queryAll(reservationInformationDetail);
        PageInfo<List> pageInfo = new PageInfo(list);
        return pageInfo;
    }
}
